package org.kjtc.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONObject;

import org.kjtc.entity.ChargingStation;
import org.kjtc.service.ChargingStationService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class GuideRequestController extends BaseController{

	@Resource(name = "chargingStationService")
	private ChargingStationService chargingStationService;

	@RequestMapping(value = "/guide")
	@ResponseBody
	public Map<String, Object> getChargingStation(HttpServletRequest request, @RequestBody String requestBody) {

		Map<String, Object> map = new HashMap<String, Object>();
		JSONObject json = JSONObject.fromObject(requestBody);
		List<ChargingStation> chargingStationList = null;
		if (json.has("chargingStationID")) {
			String chargingStationID = json.getString("chargingStationID");
			ChargingStation chargingStation = new ChargingStation();
			chargingStation.setChargingStationID(chargingStationID);
			try {
				chargingStationList = chargingStationService.getChargingStation(chargingStation);
				map.put("chargingStationList", chargingStationList);
			} catch (Exception e) {
				e.printStackTrace();
				map.put("chargingStationList", null);
			}
			chargingStation = null;
		} else {
			map.put("chargingStationList", null);
		}
		return map;
	}
}
